import './App.css';
import React,{useEffect, useState} from 'react';
import {Route,Redirect} from "react-router-dom";


// 自定义界面和组件
import {loginRoute,manageAppRoute} from './router/index';
const {component:Login,path:loginPath} = loginRoute;
const {component:ManageApp,path:manageAppPath} = manageAppRoute;


function App(props) {

  const [isLogined,setIsLogined] = useState(true);

  console.log(window.location.pathname,'---------app')

  
  useEffect(() => {
    
    if(window.localStorage.openId) {
      setIsLogined(true);
    }

  })

  return (

    
    <section className="container">

        <Route exact to="/" render={ () => isLogined?<Redirect to={manageAppPath}/>:<Redirect to={loginPath} />} />
        <Route exact to={loginPath} render={ () => isLogined?<Redirect to={manageAppPath}/>:<Login setIsLogined={setIsLogined}/> } />
        <Route exact to={manageAppPath} render={ (e) => isLogined?<ManageApp />:'' } /> 
        

    </section>
    
  );
}

export default App;
